#!/bin/bash

# refer https://zhuanlan.zhihu.com/p/128599556

if [ $# -lt 1 ] 
then 
   echo "Usage: $0 namespace"  
   exit 1 
fi 


kubectl get ns $1 -o json > name-to.json

NR=$(grep '"finalizers"'  name-to.json -n  | awk -F: '{print $1}')

TNR=$(echo $NR+1 | bc)
echo $NR,$TNR

sed -i "$TNR d"  name-to.json


kubectl proxy &


curl -k -H "Content-Type: application/json" -X PUT --data-binary @name-to.json \
http://127.0.0.1:8001/api/v1/namespaces/$1/finalize



